package karma.main;

import net.minecraft.client.Minecraft;
import net.minecraft.src.*;
import org.lwjgl.input.Keyboard;

public class ItemELLegs extends ItemArmor
{
    public static int counter;
    public static boolean notify = true;
    public static int timer = 0;
	
	public ItemELLegs(int i, EnumArmorMaterial enumarmormaterial, int j, int k)
    {
        super(i, enumarmormaterial, j, k);
    }

    public static void checkIfWorn(Minecraft minecraft)
    {
        EntityPlayerSP entityplayersp = minecraft.thePlayer;

        if (minecraft.thePlayer.inventory.armorInventory[1] != null && minecraft.thePlayer.inventory.armorInventory[1].getItem() == mod_KarmaCraft.ELLegs && !entityplayersp.isSneaking() && Keyboard.isKeyDown(mod_KarmaCraft.key.keyCode))
        {
            doSpecial(minecraft);
        }
    }

    public static void doSpecial(Minecraft minecraft)
    {
    	EntityPlayer entityplayer = ModLoader.getMinecraftInstance().thePlayer;
    	float f = 0.0F;
    	if (Math.abs(entityplayer.motionX) + Math.abs(entityplayer.motionZ) > 0.10000000149011612D)
    	{
    		if (entityplayer.inventory.hasItem(mod_KarmaCraft.MagicPowder.shiftedIndex) && counter == 0)
            {
                entityplayer.inventory.consumeInventoryItem(mod_KarmaCraft.MagicPowder.shiftedIndex);
                counter = 100;
    			f = 0.2F;
            }
    		else if (counter != 0)
    		{
    			f = 0.2F;
    		}
    		else if (counter == 0 && !entityplayer.inventory.hasItem(mod_KarmaCraft.MagicPowder.shiftedIndex))
    		{ 
    			if (notify)
    			{
    				entityplayer.addChatMessage("Not enough Magic Powder to use speed boost!");
    				notify = false;
    				timer = 20;
    			}
    		}
    	}     
    	if (counter != 0)
    	{
    		counter --;
    	}
        entityplayer.moveFlying(0.0F, 1.0F, f);
        
        if (timer > 0)
        {
        	timer --;
        	if (timer == 0)
        	{
        		notify = true;
        	}
        }
    }

    /**
     * Return an item rarity from EnumRarity
     */
    public EnumRarity getRarity(ItemStack itemstack)
    {
        return mod_KarmaCraft.ENCHANTED;
    }
}
